package com.twu.biblioteca;

import java.util.Hashtable;

public class UserManager {

    private LibraryNumber currentLibraryNumber = new LibraryNumber(111, 1111);
    private Hashtable<String, User> users = new Hashtable<String, User>();

    public void add(User user) {
        users.put(user.getUsername().toString(), user);
    }

    public User get(LibraryNumber username) {
        return users.get(username.toString());
    }

    public boolean auth(String username, String password) {
        if (users.containsKey(username)) {
            if (password.equals(users.get(username).getPassword())) {
                return true;
            }
        }
        return false;
    }

    public User generateUser() {
        User generatedUser = new User(currentLibraryNumber);
        currentLibraryNumber = currentLibraryNumber.increment();

        return generatedUser;
    }
}
